﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Validity.Rules;
using Validity.Rules.Decorators;

namespace Validity.Test.Rules.Decorators
{
  [TestClass]
  public class ConditionalDecoratorTest
  {

    private readonly Mock<IRule<ObjectStub, Object>> _baseRule;
    private readonly ObjectStub _objectStub = new ObjectStub();

    public ConditionalDecoratorTest()
    {
      _baseRule = new Mock<IRule<ObjectStub, Object>>(MockBehavior.Strict);
    }

    [TestMethod]
    public void TestIsViolatedByNotDelegatedIfPredicateEvaluatesFalse()
    {
      var rule = new ConditionalRuleDecorator<ObjectStub, Object>(_baseRule.Object, (obj, val) => false);

      Assert.IsFalse(rule.IsViolatedBy(_objectStub, "string"));
    }

    [TestMethod]
    public void TestIsViolatedByDelegatedIfPredicateEvaluatesTrue()
    {
      var rule = new ConditionalRuleDecorator<ObjectStub, Object>(_baseRule.Object, (obj, val) => true);

      _baseRule.Setup(mock => mock.IsViolatedBy(_objectStub, "string")).Returns(true);
      
      Assert.IsTrue(rule.IsViolatedBy(_objectStub, "string"));
    }
  }
}
